<template>
	<view class="container" v-if="gameInfo">
		<image class="game-banner" :src="gameInfo.game_small_background" mode="aspectFill"></image>
		
		<view class="game-info">
			<!-- 游戏标题和操作区 -->
			<view class="game-header">
				<view class="title-section">
					<text class="game-title">{{ gameInfo.game_name }}</text>
					<view class="meta-info">
						<text class="developer">{{ gameInfo.game_developer }}</text>
						<text class="publisher">{{ gameInfo.game_publisher }}</text>
					</view>
				</view>
				<view class="action-section">
					<view class="price-info">
						<text class="original-price">{{ gameInfo.price }}</text>
						<text class="current-price">限时免费</text>
					</view>
					<view class="play-btn" @click="startGame">开始游戏</view>
				</view>
			</view>
			
			<!-- 游戏标签信息 -->
			<view class="info-card">
				<view class="platform-row">
					<view class="platforms">
						<text class="platform-tag" v-for="(platform, index) in gameInfo.game_platforms" :key="index">
							{{ platform }}
						</text>
					</view>
					<text class="rating">评分：{{ gameInfo.rating }}</text>
					<text class="release-date">{{ gameInfo.release_date }}</text>
				</view>
				<view class="tags-row">
					<text class="tag" v-for="(tag, index) in gameInfo.game_tags" :key="index">{{ tag }}</text>
				</view>
			</view>
			
			<!-- 游戏简介 -->
			<view class="info-card">
				<text class="section-title">游戏简介</text>
				<view class="description-wrapper">
					<text class="game-description" :class="{ 'collapsed': !isExpanded }">
						{{ gameInfo.game_description }}
					</text>
					<view class="expand-btn" @click="toggleDescription">
						{{ isExpanded ? '收起' : '展开' }}
						<text class="expand-icon">{{ isExpanded ? '↑' : '↓' }}</text>
					</view>
				</view>
			</view>
			
			<!-- 游戏截图 -->
			<view class="info-card">
				<text class="section-title">游戏截图</text>
				<image class="screenshot" :src="gameInfo.game_long_image" mode="widthFix"></image>
			</view>
		</view>
	</view>
	<view v-else class="loading">
		<text>加载中...</text>
	</view>
</template>

<script>
import { games } from '../../utils/gameData.js'
export default {
	data() {
		return {
			gameInfo: null,
			isExpanded: false
		}
	},
	onLoad(options) {
		// 获取游戏信息
		const gameId = options.id || '1'  // 如果没有传id，默认使用1
		this.gameInfo = games.find(game => game.game_id === gameId) || games[0]
	},
	methods: {
		startGame() {
			if (this.gameInfo && this.gameInfo.game_link_url) {
				const url = this.gameInfo.game_link_url.replace('.vue', '')
				uni.navigateTo({
					url: url,
					fail: (err) => {
						console.error('导航失败:', err)
						uni.showToast({
							title: '游戏启动失败',
							icon: 'none'
						})
					}
				})
			}
		},
		toggleDescription() {
			this.isExpanded = !this.isExpanded;
		}
	}
}
</script>

<style scoped>
.container {
	min-height: 100vh;
	background: #1E1E2E;
}

.game-banner {
	width: 100%;
	height: 200px;
	margin-bottom: 15px;
}

.game-info {
	padding: 0 12px;
}

.game-header {
	background: #2D2D44;
	border-radius: 6px;
	padding: 15px;
	margin-bottom: 12px;
	display: flex;
	justify-content: space-between;
}

.title-section {
	flex: 1;
}

.game-title {
	font-size: 18px;
	color: #9796B8;
	font-weight: bold;
	margin-bottom: 8px;
	display: block;
}

.meta-info {
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.developer, .publisher {
	font-size: 12px;
	color: #6E6C89;
}

.action-section {
	text-align: right;
}

.price-info {
	margin-bottom: 8px;
}

.original-price {
	font-size: 12px;
	color: #6E6C89;
	text-decoration: line-through;
	margin-right: 6px;
}

.current-price {
	font-size: 14px;
	color: #9796B8;
	font-weight: bold;
}

.play-btn {
	background: #9796B8;
	color: #1E1E2E;
	padding: 8px 20px;
	border-radius: 6px;
	font-size: 14px;
}

.info-card {
	background: #2D2D44;
	border-radius: 6px;
	padding: 15px;
	margin-bottom: 12px;
}

.platform-row {
	display: flex;
	align-items: center;
	gap: 12px;
	margin-bottom: 12px;
}

.platforms {
	display: flex;
	gap: 6px;
}

.platform-tag {
	background: rgba(151, 150, 184, 0.1);
	color: #9796B8;
	padding: 2px 8px;
	border-radius: 4px;
	font-size: 12px;
}

.rating {
	font-size: 12px;
	color: #9796B8;
}

.release-date {
	font-size: 12px;
	color: #6E6C89;
}

.tags-row {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}

.tag {
	background: rgba(110, 108, 137, 0.1);
	color: #6E6C89;
	padding: 4px 10px;
	border-radius: 4px;
	font-size: 12px;
}

.section-title {
	font-size: 16px;
	color: #9796B8;
	margin-bottom: 12px;
	display: block;
	padding-left: 8px;
	border-left: 3px solid #9796B8;
}

.description-wrapper {
	background: rgba(30, 30, 46, 0.5);
	border-radius: 6px;
	padding: 12px;
	position: relative;
}

.game-description {
	font-size: 14px;
	color: #9796B8;
	line-height: 1.6;
	text-align: justify;
	transition: all 0.3s ease;
}

.game-description.collapsed {
	display: -webkit-box;
	-webkit-line-clamp: 3;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.expand-btn {
	text-align: center;
	color: #9796B8;
	padding: 8px 0 0;
	font-size: 13px;
	cursor: pointer;
}

.expand-icon {
	margin-left: 4px;
	font-size: 12px;
}

.screenshot {
	width: 100%;
	border-radius: 6px;
}

.loading {
	height: 100vh;
	display: flex;
	align-items: center;
	justify-content: center;
	color: #6E6C89;
	font-size: 14px;
}
</style> 
